package drds.data_migrate.task_group.task._runnable_;


import drds.common.Author;
import drds.data_migrate.Authors;
import drds.data_migrate.vo.Messages;
import drds.data_migrate.vo.State;
import drds.data_migrate.vo.Status;
import lombok.NonNull;

@Author(name = Authors.LI_YANG)
public abstract class AbstractRunnable
{


    private State state;

    private int taskGroupId;

    private int taskId;


    private void mark(Status status)
    {
        this.state.setState(status);
        if (status == Status.succeeded)
        {
            // 对 stage + 1
            this.state.setLong(Messages.stage,
                    this.state.getLong(Messages.stage) + 1);
        }
    }

    public void markRun()
    {
        mark(Status.running);
    }

    public void markSuccess()
    {
        mark(Status.succeeded);
    }

    public void markFail(final Throwable throwable)
    {
        mark(Status.failed);
        this.state.setTimestamp(System.currentTimeMillis());
        this.state.setThrowable(throwable);
    }

    public int getTaskGroupId()
    {
        return taskGroupId;
    }

    public void setTaskGroupId(int taskGroupId)
    {
        this.taskGroupId = taskGroupId;

    }

    public int getTaskId()
    {
        return taskId;
    }

    public void setTaskId(int taskId)
    {
        this.taskId = taskId;

    }

    public State getStateMessage()
    {
        return state;
    }

    public void setStateMessage(@NonNull final State state)
    {
        this.state = state;
    }

    public abstract void shutdown();
}
